<%@ page import="pojo.Teacher" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 33503
  Date: 2023/11/25
  Time: 0:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>教师信息</title>
    <style>
        table{
            width: 93.8%;
        }
        th{
            border: 1px solid #000000;
            text-align: center;
            padding: 15px 0;
            background-color: #66afe9;
            height: 40px;
            font-size: 22px;
            color: white;
        }
        td{
            border: 1px solid #000000;
            text-align: center;
            padding: 15px 0;
            height: 40px;
        }
        table tbody tr:hover{
            background-color: #a6e1ec;
        }
        #mytable th{
            text-align: center;
        }
        .content_input .my-input{/*搜索框样式*/
            margin-right: 20px;
            margin-top: 20px;
            width: 30%;
            height: 38px;
            border-radius: 5px;
            color: black;
            border: 1px solid #3388FF;
        }
        .content_input .search_btn{ /*按钮样式*/
            width: 80px;
            height: 40px;
            background-color:dodgerblue;
        }
        .content_input .search_btn:hover{ /*按钮覆盖样式*/
            background-color: #2e6da4;
            color: ivory;
        }
        .button-add{/*添加教师按钮样式*/
            width: 90px;
            height: 40px;
            margin-top: 20px;
            margin-right: 30px;
            float: left;
            background-color: #66afe9;
            border-color: #a6e1ec;
            color: white;
            font-size: large;
        }
        .button-delete{/*删除按钮样式*/
            width: 90px;
            height: 30px;
            text-align: center;
            background-color: #df5000;
            border-color: #a6e1ec;
            color: white;
            font-size: medium;
        }
        .button-delete:hover {
            background-color: #DD4A68;
        }
    </style>
</head>
<body>
<%--菜单栏--%>
<jsp:include page="management_menu.jsp"></jsp:include>
<div style="background-color: #66afe9;display: inline-block;margin-top: 10px;float: left;margin-left: 20%;height: 80px;width: 200px;text-align: center; border-radius:0px;">
    <h1 style="color:white;text-shadow: 2px 2px 2px dodgerblue;line-height: 40px;border-radius:2px;font-size: 25px">教师信息</h1>
</div>
<div style="margin-left: 35%;margin-top:10px;width: 60%;height:80px;background-color: #66afe9; ">
    <form style="padding-left: 10%" action="${pageContext.request.contextPath }/findTeacherByTeacherName" method="POST">
        <div class="content_input">
            <%--查询--%>
            <input class="my-input" type="text" name="t_name" id="t_name" placeholder="请输入教师姓名" aria-label="Search">
            <input class="btn btn-primary search_btn" type="submit" value="查询">
            <%--所有--%>
            <form style="padding-left: 10%" action="${pageContext.request.contextPath }/loadTeacherList" method="POST">
                <input type="submit" value="所有" class="btn btn-primary search_btn">
            </form>
        </div>
    </form>
</div>
<div style="margin-left: 20%">
    <div align="left">
        <input class="button-add" type="button" value="添加教师" onclick='location.href=("teacher_add.jsp")'/>
    </div>
</div>
<div  style="margin-left: 20%;margin-top: 80px">
    <table id="mytable">
        <thead>
        <tr>
            <th>工号</th>
            <th>教师姓名</th>
            <th>密码</th>
            <th>联系方式</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody>
        <!--  展示教师信息-->
        <%
            List<Teacher> teachers=(List<Teacher>)session.getAttribute("get_teachers");
            if(teachers==null||teachers.isEmpty()){
        %>
        <tr>
            <td colspan="5" style="text-align: center">数据为空</td>
        </tr>
        <%
        }else{
            for(Teacher t:teachers){
        %>
        <tr>
            <td><%=t.getT_id()%></td>
            <td><%=t.getT_name()%></td>
            <td><%=t.getT_pwd()%></td>
            <td><%=t.getT_phone()%></td>
            <td>
                <input class="button-delete" type="button" value="删除">
            </td>
        </tr>
        <%
                }}
        %>
        </tbody>
    </table>
</div>
</body>
</html>
<script>
    //删除教师
    $(function() {
        $(".button-delete").click(function() {
            var t_id=$(this).parents("tr").children("td:nth-child(1)").text();//获取点击删除对应的教师
            var content;
            if(confirm("确定删除该教师吗？")){
                content_true="删除";
                $.ajax({//传数据给controller进行删除
                    type: "post",
                    url: "${pageContext.request.contextPath }/deleteTeacher",
                    data: {
                        "t_id": t_id
                    },
                    success: function (data) {
                        console.log(data);
                        if(data==true) {//删除成功
                            alert("删除成功！")
                            window.location.replace("${pageContext.request.contextPath }/loadTeacherList");//及时刷新页面
                        }else {
                            alert("删除失败！")
                            window.location.replace("${pageContext.request.contextPath }/loadTeacherList");//及时刷新页面
                        }
                    }
                });
            }
            else {
                content_false="取消";
                window.location.replace("${pageContext.request.contextPath }/loadTeacherList");
            }
        })
    })
</script>